/*
 * Copyright (c) 2007-2020 西安交通信息投资营运有限公司 版权所有
 * 作者:张谦
 */

import React, {FC} from "react";
import permissionService from "@/pages/sys/permission/service";
import styles from "@/pages/sys/role/components/Authorize.less";
import {Tree} from "antd";
import useLoad from "@/hooks/useLoad";

const DeptScopePermission: FC<{ primaryKey: string }> = (props) => {
  const {primaryKey} = props;
  const {data: members = []} = useLoad<any>({
    isLoad: Boolean(primaryKey),
    onLoad: () => permissionService.selectUserPermissionDept(primaryKey)
  }, [primaryKey]);

  return (
    <div style={{margin: '0 24px 0 0'}}>
      {members.deptScope ? (
          <>
            <div
              className={`${styles.alert} ${styles.warning} ${styles.margin} ${styles.padding}`}>{members.deptScope}</div>
            {members.data ? (
              <li>
                <Tree
                  style={{padding: "10px 5px", overflowY: 'auto'}}
                  showIcon
                  defaultExpandAll
                  treeData={members.data}
                />
              </li>
            ) : null}</>)
        : (<div className={`${styles.alert} ${styles.warning} ${styles.margin} ${styles.padding}`}>未设置</div>)}
    </div>
  )
}

export default DeptScopePermission;
